package com.zilue.payment.gateway.method.order;

import com.zilue.payment.gateway.domain.CorpDO;
import com.zilue.payment.gateway.exception.BizManagerException;
import com.zilue.payment.gateway.manage.OrderPayManager;
import com.zilue.payment.gateway.method.BaseMethod;
import com.zilue.payment.gateway.paramter.BaseParameter;
import com.zilue.payment.gateway.paramter.order.PayParameter;
import com.zilue.payment.gateway.reurndata.PublicReturn;
import com.zilue.payment.gateway.reurndata.enums.RequestStatusEnum;
import com.zilue.payment.gateway.reurndata.order.PayReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 余额支付、积分支付、主动扫码支付
 * Created by zilue on 2017/3/7.
 */
@Service("hfpay.trade.order.pay")
public class Pay implements BaseMethod {
    @Autowired
    private OrderPayManager orderPayManager;

    @Override
    public PublicReturn doMethod(CorpDO corpDO, BaseParameter baseParameter) {
        PayParameter payParameter = (PayParameter) baseParameter;
        try {
            return orderPayManager.pay(corpDO, payParameter);
        } catch (BizManagerException ex) {
            PayReturn payReturn = new PayReturn(RequestStatusEnum.RequestSuccess);
            payReturn.setBusinessStatus(ex.getBusinessStatusEnum());
            payReturn.appendSub_msg(ex.getAppendMsg());
            return payReturn;
        }
    }

    @Override
    public Class<? extends BaseParameter> paramterClass() {
        return PayParameter.class;
    }

}
